import { BasicDrawer, useDrawerInner } from "@/components/Drawer";
import { BasicColumn, BasicTable, FormSchema, useRender, useTable } from "@/components/Table";
import { Tag } from "antd";
import "./index.less";
import { useTranslation } from "react-i18next";
import { BidCorpContractsApi } from "@/api/erp/bid/bidProContract";
import { BidReasonApi } from "@/api/erp/bid/mainReason";
import * as UserApi from "@/api/system/user";
const newAdd = (props: any) => {
	const en_vi = "drugStorage.bid";
	const { t } = useTranslation();
	const [registerDrawer, { closeDrawer }] = useDrawerInner(props.register, data => {
		console.log("data>>>>>>>>>>>>>>>", data);
	});
	const schemas: FormSchema[] = [
		{
			label: t(`${en_vi}.name`),
			field: "name",
			component: "Input"
		},
		{
			label: t(`${en_vi}.reasonId`),
			field: "reasonId",
			component: "ApiSelect",
			componentProps: {
				api: BidReasonApi.getBidReasonPage,
				labelField: "name",
				valueField: "id",
				immediate: false
			}
		},
		{
			label: t(`${en_vi}.userId`),
			field: "userId",
			component: "ApiSelect",
			componentProps: {
				api: UserApi.getListSimpleUsers,
				labelField: "nickname",
				valueField: "id",
				immediate: false
			}
		}
	];
	const columns: BasicColumn[] = [
		{
			title: t(`${en_vi}.name`),
			dataIndex: "name"
		},
		{
			title: t(`${en_vi}.year`),
			dataIndex: "year"
		},
		{
			title: t(`${en_vi}.reasonId`),
			dataIndex: "reasonId"
		},
		{
			title: t(`${en_vi}.contractNo`),
			dataIndex: "contractNo"
		},
		{
			title: t(`${en_vi}.contractDate`),
			dataIndex: "contractDate",
			render: text => useRender.renderDate(text)
		},
		{
			title: t(`${en_vi}.whsId`),
			dataIndex: "whsId"
		},
		{
			title: t(`${en_vi}.startDate`),
			dataIndex: "startDate",
			render: text => useRender.renderDate(text)
		},
		{
			title: t(`${en_vi}.endDate`),
			dataIndex: "endDate",
			render: text => useRender.renderDate(text)
		},
		{
			title: t(`${en_vi}.qty`),
			dataIndex: "qty"
		},
		{
			title: t(`${en_vi}.unitPrice`),
			dataIndex: "unitPrice"
		},
		{
			title: t(`${en_vi}.totalAmount`),
			dataIndex: "totalAmount"
		},
		{
			title: t(`${en_vi}.userId`),
			dataIndex: "userId"
		},
		{
			title: t(`${en_vi}.result`),
			dataIndex: "result"
		},
		{
			title: t(`${en_vi}.startExecDate`),
			dataIndex: "startExecDate",
			render: text => useRender.renderDate(text)
		},
		{
			title: t(`${en_vi}.endExecDate`),
			dataIndex: "endExecDate",
			render: text => useRender.renderDate(text)
		},
		{
			title: t(`${en_vi}.approvalDate`),
			dataIndex: "approvalDate",
			render: text => useRender.renderDate(text)
		},
		{
			title: t(`${en_vi}.insPrice`),
			dataIndex: "insPrice"
		},
		{
			title: t(`${en_vi}.salePrice`),
			dataIndex: "salePrice"
		},
		{
			title: t(`${en_vi}.additionalFee`),
			dataIndex: "additionalFee"
		},
		{
			title: t(`${en_vi}.priceExcludingTax`),
			dataIndex: "priceExcludingTax"
		},
		{
			title: t(`${en_vi}.tenderStatus`),
			dataIndex: "tenderStatus",
			render: (_, { currentStatus }) => (
				<>
					{currentStatus == "1" ? (
						<Tag color="success">{t("felix_ui.open")}</Tag>
					) : (
						<Tag color="error">{t("felix_ui.close")}</Tag>
					)}
				</>
			)
		},
		{
			title: t(`${en_vi}.sqNumb`),
			dataIndex: "sqNumb"
		},
		{
			title: t(`${en_vi}.biddingType`),
			dataIndex: "biddingType"
		},
		{
			title: t(`${en_vi}.currentStatus`),
			dataIndex: "currentStatus",
			render: (_, { currentStatus }) => (
				<>{currentStatus == "0" ? <Tag color="error">{t("未招标")}</Tag> : <Tag color="success">{t("已招标")}</Tag>}</>
			)
		},
		{
			title: t(`${en_vi}.shippedQty`),
			dataIndex: "shippedQty"
		},
		{
			title: t(`${en_vi}.finalStock`),
			dataIndex: "finalStock"
		},
		{
			title: t(`${en_vi}.estimatedQty`),
			dataIndex: "estimatedQty"
		}
	];
	const [registerTable, { getSelectRows }] = useTable({
		api: BidCorpContractsApi.getBidCorpContractsPage,
		columns,
		rowSelection: true,
		formConfig: {
			labelWidth: 120,
			schemas,
			showActionButtonGroup: true,
			showAdvancedButton: false,
			baseColProps: { span: 8 },
			actionColOptions: { span: 24 }
		},
		bordered: true,
		useSearchForm: true
	});
	const handleSubmit = async () => {
		const orderItem = getSelectRows();
		props.setContractNo(orderItem[0]?.id);
		closeDrawer();
	};
	return (
		<BasicDrawer
			size="large"
			{...props}
			title={t("drugStorage.selectPurchaseOrder")}
			register={registerDrawer}
			ok={handleSubmit}
			showFooter={true}
		>
			<BasicTable register={registerTable}></BasicTable>
		</BasicDrawer>
	);
};
export default newAdd;
